package com.example.webrestfulcrud.controller;

import com.example.webrestfulcrud.dao.ItemRepository;
import com.example.webrestfulcrud.dao.PanelContentRepository;
import com.example.webrestfulcrud.pojo.TbPanelContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class PanelContentController {

    @Autowired
    MongoTemplate mongoTemplate;

    @Autowired
    ItemRepository itemRepository;

    @Autowired
    PanelContentRepository panelContentRepository;

    @GetMapping("/panels")
    public ModelAndView addItemAndGetPanelContent(ModelAndView modelAndView) {

        List<TbPanelContent> all = this.panelContentRepository.findAll();

        modelAndView.addObject("panelContentList", all);

        modelAndView.setViewName("/add");

        return modelAndView;
    }
}
